#include "dialog2.h"
#include<QGridLayout>//包含布局头文件

const static double PI=3.1415926;
void Dialog2::showArea()
{
    bool ok;
    QString tempStr;
    QString valueStr=lineEdit->text();
    int valueInt=valueStr.toInt(&ok);
    double area=valueInt*valueInt*PI;

    label2->setText(tempStr.setNum(area));

}

Dialog2::Dialog2(QWidget *parent)
    : QDialog(parent)
{
    label1=new QLabel(this);//this表示父物体是该窗口程序
    label1->setText(tr("请输入圆的半径："));
    lineEdit=new QLineEdit(this);
    label2=new QLabel(this);
    button=new QPushButton(this);
    button->setText(tr("显示对应圆的面积"));

    QGridLayout *mainLayout=new QGridLayout(this);//创建布局

    mainLayout->addWidget(label1,0,0);
    mainLayout->addWidget(lineEdit,0,1);
    mainLayout->addWidget(label2,1,0);
    mainLayout->addWidget(button,1,1);
    //方式一：QPushButton::clicked()
    // connect(button,SIGNAL(clicked()),this,SLOT(showArea()));
    //方式二：QLineEdit::textChanged()
    connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(showArea()));

    setLayout(mainLayout);
    // Dialog::setLayout(mainLayout);
}

Dialog2::~Dialog2() {}
